import numpy as np
#均方误差
def mean_squared_error(y,t):
    return 0.5*np.sum((y-t)**2)
t=np.array([0,0,1,0,0,0,0,0,0,0])
y=np.array([0.1,0.05,0.6,0.0,0.05,0.1,0.0,0.1,0.0,0.0])
print(mean_squared_error(y,t))
y2=np.array([0.1,0.05,0.1,0.0,0.05,0.1,0.0,0.6,0.0,0.0])
print(mean_squared_error(y2,t))

#交叉熵误差
def cross_entropy_error(y,t):
    delta=1e-7              #保护策略，避免出现log0无限大的局面
    return -np.sum(t*np.log(y+delta))
t=np.array([0,0,1,0,0,0,0,0,0,0,])
y=np.array([0.1,0.05,0.6,0.0,0.05,0.1,0.0,0.1,0.0,0.0])
print(cross_entropy_error(y,t))
y2=np.array([0.1,0.05,0.1,0.0,0.05,0.1,0.0,0.6,0.0,0.0])
print(cross_entropy_error(y2,t))